package com.zhuiyun.educations.api.sysroleback.mapper;

import com.zhuiyun.educations.api.sysroleback.entiy.SysRoleBack;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface SysRoleBackMapper {
    /**
    * @Author MJL
    * @Description todo 角色表全查
    * @Date 2023/6/15 21:02
    * @Return  * @param null
    */
    @Select("<script>select id,role_name,role_remark,menu_ids," +
            "create_time,update_time," +
            "del_flag from sys_role " +
            "where del_flag = 0 " +
            "<when test = 'roleName != &quot;&quot; and roleName != null'>" +
            " and role_name like concat('%',#{roleName},'%') </when> " +
            "<when test = 'roleRemark != &quot;&quot; and roleRemark != null'>" +
            " and role_remark like concat('%',#{roleRemark},'%') </when> " +
            "</script>")
    List<SysRoleBack> SysRoleList(SysRoleBack sysRoleBack);

    /**
    * @Author MJL
    * @Description todo 角色表添加
    * @Date 2023/6/16 14:22
    * @Return  * @param null
    */
    @Insert("insert into sys_role (role_name,role_remark,menu_ids," +
            "create_time) values (#{roleName},#{roleRemark}," +
            "#{menuIds},#{createTime})")
    int SysRoleAdd(SysRoleBack sysRoleBack);

    /**
    * @Author MJL
    * @Description todo 角色表删除
    * @Date 2023/6/21 15:51
    * @Return  * @param null
    */
    @Update("update sys_role set del_flag = 1 where id = #{id}")
    int SysRoleUpdateDelete(Integer id);

    /**
    * @Author MJL
    * @Description todo 角色表修改
    * @Date 2023/6/21 16:06
    * @Return  * @param null
    */
    @Update("update sys_role set role_name = #{roleName}," +
            "role_remark = #{roleRemark},update_time = #{updateTime} " +
            "where id = #{id}")
    int SysRoleUpdate(SysRoleBack sysRoleBack);

    /**
    * @Author MJL
    * @Description todo 角色表分配权限
    * @Date 2023/6/23 14:59
    * @Return  * @param null
    */
    @Update("update sys_role set menu_ids = #{menuIds}," +
            "update_time = #{updateTime} where id = #{id}")
    int SysRoleAssignment(SysRoleBack sysRoleBack);

}
